package me.zhengjie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.entity.TaskList;
import me.zhengjie.mapper.TaskListMapper;
import me.zhengjie.service.TaskListService;
import org.springframework.stereotype.Service;

/**
 * @author 86181
 * @description 针对表【task_list】的数据库操作Service实现
 * @createDate 2024-04-11 16:41:59
 */
@Service
public class TaskListServiceImpl extends ServiceImpl<TaskListMapper, TaskList>
        implements TaskListService {

    private final TaskListMapper taskListMapper;

    public TaskListServiceImpl(TaskListMapper taskListMapper) {
        this.taskListMapper = taskListMapper;
    }

    @Override
    public boolean updateTask(TaskList taskList) {
        LambdaUpdateWrapper<TaskList> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(TaskList::getTargets, taskList.getTargets())
                .set(TaskList::getStatus, taskList.getStatus())
                .set(TaskList::getAgvNo, taskList.getAgvNo())
                .eq(TaskList::getTaskId, taskList.getTaskId());

        return this.taskListMapper.update(null, updateWrapper) > 0;
    }

    @Override
    public TaskList queryTask(String taskId) {
        LambdaQueryWrapper<TaskList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskList::getTaskId, taskId);

        return this.taskListMapper.selectOne(queryWrapper);
    }

    @Override
    public boolean insert(TaskList taskList) {
        return taskListMapper.insert(taskList) == 1;
    }

    @Override
    public boolean deleteByTaskId(String taskId) {
        return taskListMapper.delete(
                new QueryWrapper<TaskList>()
                        .lambda()
                        .eq(TaskList::getTaskId, taskId)
        ) == 1;
    }
}




